package com.endurance.service.impl;

import com.endurance.dao.AccountDao;
import com.endurance.pojo.Transfer;
import com.endurance.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AccountServiceImpl implements AccountService {


    @Autowired
    private AccountDao accountDao;

    @Override
    public void update(Transfer transfer1, Transfer transfer2) {
        //2.转账
        accountDao.update(transfer1);
        // 出现异常
        list();
        int i = 1 / 0;
        accountDao.update(transfer2);
    }

    @Override
    public void reset() {
        accountDao.reset(new Transfer("张三", 2000.0));
        accountDao.reset(new Transfer("李四", 6000.0));
        System.out.println("账户初始化成功！！！");
    }

    @Override
    public void list() {
        accountDao.list().forEach((x) -> System.out.println(x));
    }
}
